package com.ccq.controller;


import com.alibaba.fastjson.JSON;
import com.ccq.model.*;
import com.ccq.service.IndexService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/*
*
*前端控制器
 */

@Controller
@RequestMapping(value = { "front" })
public class IndexController {
    @Autowired
    IndexService indexService;

    @GetMapping("index")
    public String findex(HttpServletRequest request, HttpServletResponse response){
        return "index";
    }

    @GetMapping("secondlist")
    public String fsecondlist(HttpServletRequest request, HttpServletResponse response){
        return "secondlist";
    }

    @GetMapping("about")
    public String fabout(HttpServletRequest request, HttpServletResponse response){
        return "about";
    }

    @GetMapping("rentlist")
    public String frentlist(HttpServletRequest request, HttpServletResponse response){
        return "rentlist";
    }

    @GetMapping("about2")
    public String fabout2(HttpServletRequest request, HttpServletResponse response){
        return "about2";
    }

    @GetMapping("about1")
    public String fabout1(HttpServletRequest request, HttpServletResponse response){
        return "about1";
    }

    @GetMapping("newhourse")
    public String fnewhourse(HttpServletRequest request, HttpServletResponse response){
        return "newhourse";
    }

    @GetMapping("community")
    public String fcommunity(HttpServletRequest request, HttpServletResponse response){
        return "community";
    }

    @GetMapping("broker")
    public String fbroker(HttpServletRequest request, HttpServletResponse response){
        return "broker";
    }

    @GetMapping("knowledge")
    public String fknowledge(HttpServletRequest request, HttpServletResponse response){
        return "knowledge";
    }



    @ApiOperation(value="登录", notes="登录")
    @RequestMapping(value = "login",method = RequestMethod.POST)
    @ResponseBody
    public String login(@ModelAttribute User user){
        User u=indexService.checklogin(user);
        System.out.println(u.toString());
        String objJson = JSON.toJSONString(u);
        System.out.println(objJson);
        return objJson;
    }

    @ApiOperation(value="注册",notes = "注册")
    @RequestMapping(value="register",method = RequestMethod.POST)
    @ResponseBody
    public String reginster(@ModelAttribute User user){
        if(indexService.register(user)==1){
            return "1";
        }
        return "0";
    }

    @ApiOperation(value="二手房模块",notes = "二手房模块")
    @RequestMapping(value="secondok",method = RequestMethod.POST)
    @ResponseBody
    public String secondok(){
        List<Goodhourse> good=indexService.good();
        String aListJson = JSON.toJSONString(good);
        System.out.println(aListJson);
        return aListJson;
    }

    @ApiOperation(value="主页新房频道",notes = "主页新房频道")
    @RequestMapping(value="newhourse",method = RequestMethod.POST)
    @ResponseBody
    public String newhourses(){
        List<Newhourse> nh=indexService.newh();
        String aListJson = JSON.toJSONString(nh);
        System.out.println(aListJson);
        return aListJson;
    }

    @ApiOperation(value="推荐楼盘",notes = "推荐楼盘")
    @RequestMapping(value="recommend",method = RequestMethod.POST)
    @ResponseBody
    public String Recommend(){
        List<Allfloor> af=indexService.allfloor();
        String aListJson = JSON.toJSONString(af);
        System.out.println(aListJson);
        return aListJson;
    }


    @ApiOperation(value="优秀经纪人",notes = "优秀经纪人")
    @RequestMapping(value="broker",method = RequestMethod.POST)
    @ResponseBody
    public String broker(){
        List<Broker> bo=indexService.broker();
        String aListJson = JSON.toJSONString(bo);
        System.out.println(aListJson);
        return aListJson;
    }
}
